package com.bsj.sipgateway.web.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsj.power.common.config.global.JsonResult;
import com.bsj.power.common.def.entity.log.CmdLog;
import com.bsj.power.common.mapper.CmdLogMapper;
import com.bsj.sipgateway.web.service.CmdLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @Description
 * @Author zhaoyang
 * @Date 2024/11/19 10:41
 */
@Slf4j
@Service("cmdLogServiceImpl")
public class CmdLogServiceImpl implements CmdLogService {

    @Autowired
    private CmdLogMapper cmdLogMapper;

    @Override
    public JsonResult listCmdLogs(String nickName, String beginTime, String endTime, Integer pageNumber, Integer pageSize) {
        IPage<CmdLog> page = new Page<>(pageNumber, pageSize);
        QueryWrapper<CmdLog> queryWrapper = new QueryWrapper<>();
        if (nickName != null) {
            queryWrapper.like("device_name", nickName);
        }
        queryWrapper.between("time", beginTime, endTime);
        queryWrapper.orderByDesc("time");
        IPage<CmdLog> cmdLogIPage = cmdLogMapper.selectPage(page, queryWrapper);

        JsonResult jsonResult = JsonResult.success();
        jsonResult.setData(cmdLogIPage.getRecords());
        jsonResult.setTotal(cmdLogIPage.getTotal());
        return jsonResult;
    }
}
